[#ftl]
[@define "agile.form._FormWidget" "agile._Component"]
	[#assign templateString][#compress]			
	<div class="agileComponent agile{widgetName} agileField" style="position:absolute;left:{style.left};top:{style.top}">
		<span data-dojo-attach-point="delegate" data-dojo-type="dijit/form/{widgetName}"></span>
	</div>
	[/#compress][/#assign]
	templateString:"${templateString?js_string}"
	,attributes:agile.delegate(agile._Component.prototype.attributes,{		
		disabled:lang.mixin({},agile.BooleanMetadata,{			
			toHtml:function(value,widget,sourceType){
				return value?"disabled":"";	
			}
			,label:"i18n_disabled"
		})	
		//,title: lang.mixin({},agile.TextMetadata ,{label:"i18n_title"})
	})
	,initDefaultMetadata:function(){
		this.metadata("style.width","120px");
		this.metadata("style.height","20px");
		this.metadata("parameters.value","");
	}
	,constructor:function(){
		if(this.widgetName && this.widgetName != "null"){
			var dojoDeclaredClass = "dijit.form." + this.widgetName;
			agile.requireX(dojoDeclaredClass);
			this.metadata("dojoDeclaredClass",dojoDeclaredClass);
		}
	}
	,init:function(){		
		if(this._initFormWidget){
			return true;
		}
		this._initFormWidget = true;
				
		this.delegate.parent = this;

		style.set(this.delegate.domNode,{width:this.metadata("style.width"),height:this.metadata("style.height")});
		
		var parameters = this.metadata("parameters");
//		console.log(this.declaredClass,"attributes=",this.attributes,",parameters=",parameters);
		for(var name in this.attributes){
			if(!this.attributes[name].ignore(this,"dojo")){
				var value = lang.getObject(name,false,parameters);
				if(value != null){
					value = this.attributes[name].parse(value);
				}
				if(value != this.attributes[name].defaultValue){
//					console.log(lang.replace("@@@@@@@@@@set name={0} value={1}",[name,value]));
					//lang.setObject(name,value,this.delegate);					
					if(name.indexOf("constraints.") == 0){
						this.delegate.constraints[name.replace("constraints.","")] = value;
					}else{
						this.delegate.set(name,value);
					}
				}
			}			
		}
		this.delegate.set("value",this.metadata("parameters.value"));
		
		//aspect.after(this.delegate,"onChange",lang.hitch(this,"onValueChange"),true);
		this.delegate.watch("value",lang.hitch(this,function(name,oldValue,newValue){
			this.onValueChange(newValue);
		}));
		agile.backspace(this.delegate);
	}
	,onValueChange:function(newValue){
		topic.publish("agile.widget.changed",this.category,"value",newValue);					
		this.metadata("parameters.value",newValue);	
	}
[/@]

